<template>
  <div class="file-list">
    <Breadcrumb :listQuery="listQuery" :pageObj="pageObj" />
    <el-empty v-show="!tableData.length" description="暂无数据"></el-empty>
    <FileItem :tableData="tableData" />
    <div style="clear: both"></div>
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
  </div>
</template>
<script>
export default {
  components: {
    Breadcrumb: () => import('./Breadcrumb.vue'),
    FileItem: () => import('./FileItem.vue'),
  },
  data() {
    return {
      listQuery: {
        king: 1, //1.我的网盘，2.全部网盘 3.我的回收站 4.移动时选择目录
        category: 1,
        del: 1,
        limit: 50,
        page: 1,
        pId: 0,
      },
      tableData: [],
      pageObj: {},
    }
  },
  watch: {
    'listQuery.pId': {
      immediate: true,
      handler(pid) {
        this.$store.dispatch('setPid', pid)
      },
    },
  },
  mounted() {
    this.getList()
    this.$bus.$on('refreshTbNetDiskList', (v) => {
      if (v) {
        Object.assign(this.listQuery, v)
      }
      this.getList()
    })
  },
  beforeDestroy() {
    this.$bus.$off('refreshTbNetDiskList')
  },
  methods: {
    async getList() {
      let res = await this.$store.dispatch('queryTbNetDisk', this.listQuery)
      this.tableData = res.data
      this.pageObj = res
      this.$store.dispatch('setFileList', this.tableData)
    },
  },
}
</script>
<style scoped lang="scss">
.file-list {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}
</style>